import request from '@/utils/request'

// 首页-反馈-不喜欢文章
export const dislikeArticleAPI = (artId) => request({
  url: '/v1_0/article/dislikes',
  method: 'POST',

  data: {
    target: artId
  }
})
// 举报文章
export const articleReportsAPI = ({ artId, type }) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'POST',
    data: {
      target: artId,
      type: type,
      remark: '就是对文章不喜欢'
    }

  })
}

// 评论 - 获取文章的评论列表
export const getCommentsListAPI = ({ artId, offset = null, limit = 10, type = 'a' }) => request({
  url: '/v1_0/comments',
  params: {
    type: type,
    source: artId,
    offset: offset, // axios遇到值为null时,会忽略当前参数key的值 null
    linmit: limit
  }
})
// 评论 -点赞
export const likeCommentAPI = (commentId) => request({
  url: '/v1_0/comment/likings',
  method: 'POST',
  data: {
    target: commentId
  }
})
// 评论- 取消点赞
export const unLikeCommentAPI = (commentId) => request({
  url: `/v1_0/comment/likings/${commentId}`,
  method: 'DELETE'

})

// 评论 - 发布评论
export const sendCommentAPI = ({ target, content, artId = null }) => {
  const obj = {
    target: target, // 文章id或评论id
    content: content
  }
  if (artId !== null) {
    obj.art_id = artId
  }
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj
  })
}
